﻿using System.Drawing;
using System.Windows.Forms;

namespace BLL
{
    public class UIBLL
    {
        private static readonly object LabMsgLock = new object();
        private static readonly object TextBoxMsgLock = new object();
        private static readonly object ButtonLock = new object();
        private delegate void invokehandler();
        public void LabelShowMsg(Label label, string msg)
        {
            lock (LabMsgLock)
            {
                label.Invoke(new invokehandler(delegate ()
                {
                    label.Text = msg;
                }));
            }
        }
        public void TextBoxShowMsg(TextBox textBoxRec, string msg)
        {
            lock (TextBoxMsgLock)
            {
                textBoxRec.Invoke(new invokehandler(delegate ()
                {
                    if (!msg.Contains("\r\n"))
                    {
                        msg += "\r\n";
                    }
                    textBoxRec.AppendText( msg);
                    textBoxRec.ScrollToCaret();
                }));
            }
        }
        public void SetButton(Button button, Color color, bool enable)
        {

            button.Invoke(new invokehandler(delegate ()
            {
                button.Enabled = enable;
                button.BackColor = color;
            }));

        }
    }
}
